package com.lsa.letcode.the54.spiralMatrix;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;

public class SpiralMatrixTest {
	@Test
	public void test(){
		Solution s = new Solution();
		test(s, new int[0][0], new ArrayList<Integer>());
		test(s, new int[][] { { 1 } }, Arrays.asList(1));
		test(s, new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } },
				Arrays.asList(1, 2, 3, 6, 9, 8, 7, 4, 5));
		
		test(s,
				new int[][]{{1,2},{3,4}},
				Arrays.asList(1, 2, 4, 3));
		
		test(s,
				new int[][] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } },
				Arrays.asList(1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7));
		
		test(s, new int[][] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 },
				{ 9, 10, 11, 12}, {13, 14, 15, 16 } }, Arrays.asList(1, 2, 3, 4,
				8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10));
		
		test(s, new int[][] { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 },
				{ 11, 12, 13, 14, 15 }, { 16, 17, 18, 19, 20 } }, Arrays.asList(1, 2, 3, 4, 5, 10, 15,
				20, 19, 18, 17, 16, 11, 6, 7, 8, 9, 14, 13, 12));

		test(s, new int[][] { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 },
				{ 11, 12, 13, 14, 15 }, { 16, 17, 18, 19, 20 },
				{ 21, 22, 23, 24, 25 } }, Arrays.asList(1, 2, 3, 4, 5, 
						10, 15, 20, 25, 
						24, 23, 22, 21, 
						16, 11, 6, 
						7, 8, 9, 
						14, 19, 18, 17,
						12, 13));
	}

	private void test(Solution s, int[][] input, List<Integer> expected) {
		List<Integer> actual = s.spiralOrder(input);
		Assert.assertEquals(expected, actual);
	}
}
